/**
 * Copyright 2011 Mathieu Magnaudet
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package edu.enac.geoapp.model;

import java.util.ArrayList;
import java.util.List;

/**
 * Enum for Meteo France Products. Provides a method to get the product
 * corresponding to the name found in a String, typically a filename
 * 
 * @author mathieu
 * 
 */
public enum Product {
	SIGMET("SGM"), METAR("MTR"), TAF("TAF"), TEMPERATURE("GRT"), VENT("GRV"), TEMSI_FRANCE(
			"TMF"), TEMSI_EUROPE("TME"), SAT_VIS("VIS"), SAT_IR("IR"), WIMS_CB(
			"CB_"), WIMS_CAT("CAT"), WIMS_ICE("ICE"), RADAR("RAD");

	private final String prefix;
	private static List<Product> productList = new ArrayList<Product>();

	static {
		productList.add(SIGMET);
		productList.add(METAR);
		productList.add(TAF);
		productList.add(TEMPERATURE);
		productList.add(VENT);
		productList.add(TEMSI_FRANCE);
		productList.add(TEMSI_EUROPE);
		productList.add(SAT_VIS);
		productList.add(SAT_IR);
		productList.add(WIMS_ICE);
		productList.add(WIMS_CB);
		productList.add(WIMS_CAT);
		productList.add(RADAR);
	}

	Product(String name) {
		this.prefix = name;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return prefix;
	}

	/**
	 * Returns the product whose name is contained in the given string
	 * 
	 * @param substring
	 *            A string containing a product name
	 * @return the product or null if no corresponding product has been found
	 */
	public static Product getProduct(String substring) {
		for (Product p : productList) {
			if (substring.contains(p.prefix)) {
				return p;
			}
		}
		return null;
	}

}
